using System;
using System.Collections.Generic;
using System.Text;

namespace MMYY.BLL
{
    public class Type
    {
        private IDAL.IType dal = DALFactory.DataAccess.CreateType();
        
        public IList<Model.Type> Get(byte type)
        {
            return dal.Get(type);
        }

        public IList<Model.Type> Get(int upid,byte type)
        {
            return dal.Get(upid,type);
        }

        public int GetSubTypeNum()
        {
            int subNums = 0;
            if (System.Web.HttpContext.Current.Cache["SubTypeNum"] != null)
            {
                subNums = (int)(System.Web.HttpContext.Current.Cache["SubTypeNum"]);
            }
            else
            {
                IList<Model.Type> Iroots = dal.Get(0, 0);
                List<Model.Type> roots = Iroots as List<Model.Type>;
                IList<Model.Type> Isubs = null;
                foreach (Model.Type t in roots)
                {
                    Isubs = dal.Get(t.m_id, 0);
                    subNums += Isubs.Count;
                }
                System.Web.HttpContext.Current.Cache["SubTypeNum"] = subNums;
            }
            return subNums;
        }

        public Model.Type GetSingle(int typeid)
        {
            return dal.GetSingle(typeid);
        }
    }
}
